#include "CollaborationProtocol.h"
#include <string>
#include <sstream>

// 简化版本，避免wxWidgets依赖
CollaborationMessage::CollaborationMessage()
    : m_type(MODEL_EDIT)
{
    m_messageId = GenerateMessageId();
}

CollaborationMessage::CollaborationMessage(MessageType type, const wxString& sender, const wxString& content)
    : m_type(type), m_sender(sender), m_content(content)
{
    m_messageId = GenerateMessageId();
}

wxString CollaborationMessage::Serialize() const
{
    wxString data;
    data << m_type << "|" << m_sender << "|" << m_content << "|" << m_messageId;
    return data;
}

bool CollaborationMessage::Deserialize(const wxString& data)
{
    wxArrayString tokens = wxStringTokenize(data, "|");
    if (tokens.size() < 4) return false;

    long type;
    if (!tokens[0].ToLong(&type)) return false;
    m_type = static_cast<MessageType>(type);
    
    m_sender = tokens[1];
    m_content = tokens[2];
    m_messageId = tokens[3];
    
    return true;
}

wxString CollaborationMessage::GenerateMessageId() const
{
    static int counter = 0;
    counter++;
    return wxString::Format("msg_%d", counter);
}
